
#import "WWThumbWheel.h"
#import "WWThumbWheelCell.h"

@implementation WWThumbWheel

static id myStoredCellClass;


+ initialize 
{ 
  [WWThumbWheel setVersion:1]; 

  if (self == [WWThumbWheel class])
  {  myStoredCellClass = [WWThumbWheelCell class];
  }

  return self; 
}
//
+ setCellClass:classID
{
  myStoredCellClass = classID;
  return self;
}
////////////////////////////////////////////////////////
//
- initFrame:(const NXRect *)frameRect
{
  id  oldCell;


  [super initFrame:frameRect];
  oldCell = [self setCell:[[myStoredCellClass alloc] init]];
  [oldCell free];

  return self;
}
//
- awakeFromNib
{
  [visibleMinText setFloatValue:[self visibleMin]];
  [visibleMaxText setFloatValue:[self visibleMax]];
  [absoluteMinText setFloatValue:[self absoluteMin]];
  [absoluteMaxText setFloatValue:[self absoluteMax]];
  [valText setFloatValue:[self floatValue]];
  [relativeValText setFloatValue:[self relativeFloatValue]];
  return self;
}
//
- setVisibleMin:(float)value
{
   [visibleMinText setFloatValue:value];
   return [super setVisibleMin:value];
}
//
- setVisibleMax:(float)value
{
   [visibleMaxText setFloatValue:value];
   return [super setVisibleMax:value];
}
//
- setAbsoluteMin:(float)value
{
   [absoluteMinText setFloatValue:value];
   return [super setAbsoluteMin:value];
}
//
- setAbsoluteMax:(float)value
{
   [absoluteMaxText setFloatValue:value];
   return [super setAbsoluteMax:value];
}
// need this because there is no equivalent to awakeFromNib inside of IB...
static BOOL oTheHorrorOfItAll = YES;

- sendAction:(SEL)theAction to:theTarget
{
  if (oTheHorrorOfItAll)
  {  oTheHorrorOfItAll = NO;
     [visibleMaxText setFloatValue:[self visibleMax]];
     [visibleMinText setFloatValue:[self visibleMin]];
     [absoluteMaxText setFloatValue:[self absoluteMax]];
     [absoluteMinText setFloatValue:[self absoluteMin]];
  }
  [valText setFloatValue:[self floatValue]];
  [relativeValText setFloatValue:[self relativeFloatValue]];
  if ([cell respondsTo:@selector(updateInterp)])
  {  [cell updateInterp];
  }
  return [super sendAction:theAction to:theTarget];
}

- setStringValue:(const char *)str
{
  char  *theStr;

  [super setStringValue:str];
  theStr = (char *)[self stringValue];
  [visibleMaxText setStringValue:theStr];
  [visibleMinText setStringValue:theStr];
  [absoluteMaxText setStringValue:theStr];
  [absoluteMinText setStringValue:theStr];
  [valText setStringValue:theStr];
  [relativeValText setStringValue:theStr];
  [self display];
  return self;
}

- setIntValue:(int)val
{
  int   theVal;


  [super setIntValue:val];
  theVal = [self intValue];
  [visibleMaxText setIntValue:theVal];
  [visibleMinText setIntValue:theVal];
  [absoluteMaxText setIntValue:theVal];
  [absoluteMinText setIntValue:theVal];
  [valText setIntValue:theVal];
  [relativeValText setIntValue:theVal];
  [self display];
  return self;
}

- setFloatValue:(float)val
{
  float  theVal;


  [super setFloatValue:val];
  theVal = [self floatValue];
  [visibleMaxText setFloatValue:theVal];
  [visibleMinText setFloatValue:theVal];
  [absoluteMaxText setFloatValue:theVal];
  [absoluteMinText setFloatValue:theVal];
  [valText setFloatValue:theVal];
  [relativeValText setFloatValue:theVal];
  [self display];
  return self;
}

// need to be able to see the cell's tclVar...
- setTclVar:(const char *)str { return [[self cell] setTclVar:str]; }
- (const char *)tclVar { return [[self cell] tclVar]; }

// need to be able to see the cell's controlString...
- setControlString:(const char *)str { return [[self cell] setControlString:str]; }
- (const char *)controlString { return [[self cell] controlString]; }

// need to be able to see the cell's tclExpression...
- setTclExpression:(const char *)str { return [[self cell] setTclExpression:str]; }
- (const char *)tclExpression { return [[self cell] tclExpression]; }

- setInterp:newInterp {  return [[self cell] setInterp:newInterp]; }
- evaluateSelf { [[self cell] evaluateSelf]; return [self display]; }

// IB stuff
- (const char *)getInspectorClassName 
{  
   NXEvent  *event = [NXApp currentEvent];

   if (event->flags & NX_ALTERNATEMASK)
   {  return [super getInspectorClassName];
   }
   
   return "WWThumbWheelIBInspector"; 
}

- write:(NXTypedStream *)stream 
{
   [super write:stream];
   return self;
}
//
- read:(NXTypedStream *)stream 
{
   int version;

   [super read:stream];

   version = NXTypedStreamClassVersion(stream, "WWThumbWheel");
   if (version == 1)
   {  
   }
   return self;
}

@end
